<?php
	include("porter.php");

	function initialSearch()
	{
		// get query from address bar
		$searchQuery = $_GET['search'];
		
		// figure out which table are we searching from
		$searchType = trim($_GET['searchType']) . "s_table";
		
		// make query for SIMILAR searchQueries, and order by title, then popularity
		// page rank still not done
		$query = "SELECT * LIKE $searchQuery FROM $searchType ORDER BY title, pageviews";
		$response = mysql_query($query);
		
		// for guest users, they have a limit on what they can see.
		$guestLimit = 0;
		if ($response)
		{
			while($results = mysql_fetch_array($response))
			{
				// if we reach the limit for guest, stop getting any more queries.
				if ($guestLimit == 3)
					break;
					
				if (!isset($_SESSION['user']))
					$guestLimit++;

				$filename = $results['Filename'];
				$UID = $results['uid'];
				$CID = $results['CID'];
				
				// look for the username
				$entry = mysql_query("SELECT Username FROM user_table WHERE uid=$UID");						
				$entry = mysql_fetch_array($entry);
				$userName = $entry['Username'];
				
				// place all search results in an array
				$searchResults[] = array($filename, $userName, $UID, $CID);
			}			
		}
		return $searchResults;
	}
	
	function nextSearchListing()
	{
	}

?>